package com.cacshanghai.cac_oa_client.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.Switch;

import com.cacshanghai.cac_oa_client.R;
import com.cacshanghai.cac_oa_client.beans.Daily;
import com.cacshanghai.cac_oa_client.widget.MyInnerScrollView;
import com.cacshanghai.cac_oa_client.widget.NoScrollListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by geyh on 2016/5/25.
 */
public class DailyFormFragment extends Fragment {

    private Switch sw_overtime, sw_travel;
    private LinearLayout ll_overtime, ll_travel;

    private List<Daily> dailyList = new ArrayList<>();
    private NoScrollListView lv_daily;
    private MyInnerScrollView myInnerScrollView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_daily_form, null);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        setData();
        lv_daily = (NoScrollListView) getView().findViewById(R.id.lv_daily);
        lv_daily.setAdapter(dailyAdapter);

        myInnerScrollView = (MyInnerScrollView) getView().findViewById(R.id.sv_form);


        initSwitch();

    }

    private void setData() {
        dailyList.add(new Daily());
        dailyList.add(new Daily());
        dailyList.add(new Daily());
    }

    //加班出差开关设置
    private void initSwitch() {
        sw_overtime = (Switch) getView().findViewById(R.id.sw_overtime);
        sw_travel = (Switch) getView().findViewById(R.id.sw_travel);
        ll_overtime = (LinearLayout) getView().findViewById(R.id.ll_overtime);
        ll_travel = (LinearLayout) getView().findViewById(R.id.ll_travel);
        sw_overtime.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ll_overtime.setVisibility(View.VISIBLE);
                } else {
                    ll_overtime.setVisibility(View.GONE);
                }
            }
        });
        sw_travel.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    ll_travel.setVisibility(View.VISIBLE);
                } else {
                    ll_travel.setVisibility(View.GONE);
                }
            }
        });
    }

    private BaseAdapter dailyAdapter = new BaseAdapter() {
        @Override
        public int getCount() {
            return dailyList.size();
        }

        @Override
        public Daily getItem(int position) {
            return dailyList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_daily, null);
            }

            return convertView;
        }
    };


}
